package com.burstly.lib.component;

import android.content.Context;
import com.burstly.lib.network.ResponseObject;
import com.burstly.lib.network.beans.RequestData;
import com.burstly.lib.network.beans.ResponseBean;
import com.burstly.lib.network.beans.ResponseBean.ResponseData;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

public final class ComponentFactory
{
  private static final String BURSTLY_ADAPTOR_FACTORY = "com.burstly.lib.component.networkcomponent.burstly.BurstlyAdaptorFactory";
  private static final String BURSTLY_IMAGE = "BURSTLY_IMAGE";
  private static final String BURSTLY_SCRIPT = "BURSTLY_SCRIPT";
  private static final String BURSTLY_TEXT = "BURSTLY_TEXT";
  private static final String BURSTLY_VIDEO = "BURSTLY_VIDEO";
  private static final ThreadLocal<String> BURSTLY_VIEW_ID = new ThreadLocal();
  private static final ThreadLocal<String> CURRENT_NETWORK_NAME;
  private static final String FACTORY_CLASS = "factoryClass";
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final ThreadLocal<String> LOG_TAG = new ThreadLocal();

  static
  {
    CURRENT_NETWORK_NAME = new ThreadLocal();
  }

  private static ComponentQueueElement createBurstlyQueueElement(String paramString, ResponseBean.ResponseData paramResponseData)
  {
    String str;
    if ((Utils.isSimpleText(paramResponseData)) || (Utils.isTextImage(paramResponseData)))
      str = "BURSTLY_TEXT";
    while (str != null)
    {
      BurstlyComponentQueueElement localBurstlyComponentQueueElement = new BurstlyComponentQueueElement(paramString, str, "com.burstly.lib.component.networkcomponent.burstly.BurstlyAdaptorFactory");
      localBurstlyComponentQueueElement.setFactoryId("burstly");
      return localBurstlyComponentQueueElement;
      if (Utils.isBanner(paramResponseData))
      {
        str = "BURSTLY_IMAGE";
      }
      else if (Utils.isScript(paramResponseData))
      {
        str = "BURSTLY_SCRIPT";
      }
      else
      {
        boolean bool = Utils.isVideo(paramResponseData);
        str = null;
        if (bool)
          str = "BURSTLY_VIDEO";
      }
    }
    LOG.logInfo((String)LOG_TAG.get(), "Unsupported Burstly ad.", new Object[0]);
    return null;
  }

  private static ComponentQueueElement createThirdPartyQueueElement(String paramString1, String paramString2)
  {
    String str1 = Utils.get3rdPartySdkName(paramString2);
    CURRENT_NETWORK_NAME.set(str1);
    if (paramString2.indexOf("factoryClass") != -1);
    for (String str2 = (String)Utils.fromJson(Utils.get3rdPartySdkParams(paramString2)).get("factoryClass"); ; str2 = Utils.extractFactoryClassName(str1))
      return new ComponentQueueElement(paramString1, str1, str2);
  }

  public static Collection<ComponentQueueElement> getComponents(Context paramContext, String paramString, ResponseBean paramResponseBean, RequestData paramRequestData)
  {
    setLogTag(paramString);
    return getSpecificComponents(paramContext, paramString, paramResponseBean, paramRequestData);
  }

  private static Collection<ComponentQueueElement> getSpecificComponents(Context paramContext, String paramString, ResponseBean paramResponseBean, RequestData paramRequestData)
  {
    ArrayList localArrayList = new ArrayList();
    ResponseBean.ResponseData[] arrayOfResponseData = paramResponseBean.getData();
    if ((arrayOfResponseData != null) && (arrayOfResponseData.length > 0))
    {
      int i = arrayOfResponseData.length;
      int j = 0;
      if (j < i)
      {
        ResponseBean.ResponseData localResponseData = arrayOfResponseData[j];
        setExpirationTime(localResponseData);
        ComponentQueueElement localComponentQueueElement;
        if (Utils.isThirdPartySDK(localResponseData))
        {
          localComponentQueueElement = createThirdPartyQueueElement(paramString, localResponseData.getParms());
          label72: if (localComponentQueueElement == null)
            break label123;
          localComponentQueueElement.setCreativeData(localResponseData);
          localComponentQueueElement.setFullResponse(paramResponseBean);
          localComponentQueueElement.setFullRequest(paramRequestData);
          localArrayList.add(localComponentQueueElement);
        }
        while (true)
        {
          j++;
          break;
          localComponentQueueElement = createBurstlyQueueElement(paramString, localResponseData);
          break label72;
          label123: LoggerExt localLoggerExt = LOG;
          String str = (String)LOG_TAG.get();
          Object[] arrayOfObject = new Object[1];
          arrayOfObject[0] = CURRENT_NETWORK_NAME.get();
          localLoggerExt.logError(str, "{0} is an unsupported network!", arrayOfObject);
        }
      }
    }
    else
    {
      LOG.logInfo((String)LOG_TAG.get(), "No Ads available...", new Object[0]);
    }
    return localArrayList;
  }

  private static long minutesToMillisec(Integer paramInteger)
  {
    return 1000 * (60 * paramInteger.intValue());
  }

  private static void setExpirationTime(ResponseBean.ResponseData paramResponseData)
  {
    Integer localInteger = paramResponseData.getExpires();
    if ((localInteger != null) && (paramResponseData.getExpiresAfter() == null))
      paramResponseData.setExpiresAfter(Long.valueOf(minutesToMillisec(localInteger) + System.currentTimeMillis()));
    if ((paramResponseData.getExpiresAfter() != null) && (LoggerExt.getLogLevel() == 3))
    {
      LoggerExt localLoggerExt = LOG;
      String str = (String)LOG_TAG.get();
      Object[] arrayOfObject = new Object[2];
      arrayOfObject[0] = new Date(paramResponseData.getExpiresAfter().longValue());
      arrayOfObject[1] = paramResponseData;
      localLoggerExt.logDebug(str, "Ad expires at {0} {1}", arrayOfObject);
    }
  }

  private static void setLogTag(String paramString)
  {
    BURSTLY_VIEW_ID.set(paramString);
    LOG_TAG.set(MessageFormat.format("ComponentFactory for {0}", new Object[] { paramString }));
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.ComponentFactory
 * JD-Core Version:    0.6.2
 */